package com.anyou.mall.sho.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.common.annotation.ShopScope;
import com.anyou.common.core.domain.*;
import com.anyou.common.utils.bean.BeanUtils;
import com.anyou.mall.index.param.CarPartsShopParam;
import com.anyou.mall.partner.domain.PartnerLavel;
import com.anyou.mall.rule.domain.JfRule;
import com.anyou.mall.rule.service.IJfRuleService;
import com.anyou.mall.sho.param.*;
import com.anyou.mall.sho.vo.CarPartsShopDetailsVo;
import com.anyou.mall.sho.vo.CarPartsShopListVo;
import com.baomidou.mybatisplus.extension.api.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.sho.domain.CarPartsShop;
import com.anyou.mall.sho.service.ICarPartsShopService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 汽配商列表Controller
 *
 * @author gaochaohao
 * @date 2022-03-18
 */
@Api(tags = "合伙人列表")
@RestController
@RequestMapping("/sho/carPartsShop")
public class CarPartsShopController extends BaseController
{
    @Autowired
    private ICarPartsShopService carPartsShopService;
    @Autowired
    private IJfRuleService jfRuleService;

    /**
     * 查询汽配商列表列表
     */
    @ApiOperation("查询合伙人列表")
    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:list')")
    @GetMapping("/list")
    public TableDataInfo<List<CarPartsShopListVo>> list(CarPartsShop carPartsShop)
    {
        startPage();
        List<CarPartsShopListVo> list = carPartsShopService.selectCarPartsShopList(carPartsShop);
        return getDataTable(list);
    }
    /**
     * 修改合伙人区域
     */
    @ApiOperation("修改合伙人区域")
    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:editArea')")
    @PostMapping("/editArea")
    public ApiResult editArea(EditAreaDto param)
    {
        carPartsShopService.editArea(param);
        return ApiResult.success();
    }

    /**
     * 导出汽配商列表列表
     */
    @ApiOperation("导出商家列表列表")
    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:export')")
    @Log(title = "汽配商列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarPartsShop carPartsShop)
    {
        List<CarPartsShopListVo> list = carPartsShopService.selectCarPartsShopList(carPartsShop);
        ExcelUtil<CarPartsShopListVo> util = new ExcelUtil<CarPartsShopListVo>(CarPartsShopListVo.class);
        util.exportExcel(response, list, "汽配商列表数据");
    }

    /**
     * 获取汽配商列表详细信息
     */
    @ApiOperation("获取详细信息")
    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:query')")
    @GetMapping(value = "/{carPartsShopId}")
    public ApiResult<CarPartsShop> getInfo(@PathVariable("carPartsShopId") Long carPartsShopId)
    {
        CarPartsShop carPartsShop = carPartsShopService.selectCarPartsShopDetailsByCarPartsShopId(carPartsShopId);
        ApiResult<CarPartsShop>  res = ApiResult.success(carPartsShop);
        return  res;
    }




    /**
     * 新增汽配商列表
     */
    @ApiOperation("新增合伙人")
    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:add')")
    @Log(title = "新增合伙人", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody AddPartsShopParam param)
    {
        CarPartsShop carPartsShop = new CarPartsShop();
        BeanUtils.copyProperties(param,carPartsShop);
        carPartsShop.setSourceType(1);
        int i = carPartsShopService.insertCarPartsShop(carPartsShop);
        return ApiResult.success();
    }

    /**
     * 修改汽配商列表
     */
    @ApiOperation("修改合伙人信息")
    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:edit')")
    @Log(title = "修改合伙人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody AddPartsShopParam2 param)
    {
        return ApiResult.success(carPartsShopService.updateCarPartsShop(param));
    }
//    /**
//     * 店铺管理-店铺设置
//     */
//    @ApiOperation("店铺管理-店铺设置")
//    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:set')")
//    @Log(title = "店铺设置", businessType = BusinessType.UPDATE)
//    @PostMapping("/set")
//    public ApiResult set(@RequestBody CarPartsShopParam2 carPartsShop)
//    {
//        CarPartsShop carPartsShop1 = new CarPartsShop();
//        BeanUtils.copyProperties(carPartsShop,carPartsShop1);
//        return ApiResult.success(carPartsShopService.updateCarPartsShop(carPartsShop1));
//    }

    /**
     * 删除汽配商列表
     */
    @ApiOperation("删除合伙人")
    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:remove')")
    @DeleteMapping("/{carPartsShopIds}")
    public ApiResult remove(@PathVariable Long[] carPartsShopIds)
    {
        return ApiResult.success(carPartsShopService.deleteCarPartsShopByCarPartsShopIds(carPartsShopIds));
    }

    /**
     * 修改状态
     */
    @ApiOperation("修改状态")
    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:disable')")
    @Log(title = "汽配商列表", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/EnableStatus/{carPartsShopId}")
    public ApiResult updateEnableStatus(@PathVariable("carPartsShopId") Long carPartsShopId)
    {
        return carPartsShopService.updateEnableStatus(carPartsShopId);
    }
    @ApiOperation("会员等级下拉列表")
    @GetMapping("/getLavelList")
    public ApiResult<List<PartnerLavel>> getLavelList()
    {
        List<PartnerLavel> list = carPartsShopService.getLavelList();
        return ApiResult.success(list);
    }

//    /**
//     * 设置首页推荐
//     */
//    @ApiOperation("设置首页推荐")
//    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:recommendation')")
//    @Log(title = "汽配商列表", businessType = BusinessType.UPDATE)
//    @PostMapping(value = "/IsHomeRecommend/{carPartsShopId}")
//    public ApiResult updateIsHomeRecommend(@PathVariable("carPartsShopId") Long carPartsShopId)
//    {
//        return carPartsShopService.updateIsHomeRecommend(carPartsShopId);
//    }



    @ApiOperation("商家下拉列表")
    @GetMapping("/getAllList")
    @ShopScope(baseTableAlias="a")
    public ApiResult<List<CarPartsShop>> getAllList(CarPartsShop carPartsShop)
    {
        List<CarPartsShop> list = carPartsShopService.getAllList(carPartsShop);
        return ApiResult.success(list);
    }

//    /**
//     * 修改是否是授权店
//     */
//    @ApiOperation("修改是否是授权店")
//    @PreAuthorize("@ss.hasPermi('sho:carPartsShop:authorizeAgent')")
//    @Log(title = "汽配商列表", businessType = BusinessType.UPDATE)
//    @PostMapping(value = "/authorizeAgent")
//    public ApiResult updateAuthorizeAgent(@RequestBody IsAuthorizeAgentParam2 isAuthorizeAgentParam2)
//    {
//        return carPartsShopService.updateAuthorizeAgent(isAuthorizeAgentParam2);
//    }
}
